package com.cloud.product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.common.entity.ShopProduct;
import com.cloud.product.dao.ShopProductDao;
import com.cloud.product.service.ShopProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 产品 服务实现类
 * </p>
 *
 * @author 李均华
 * @since 2021-06-04
 */
@Service
@Slf4j
public class ShopProductServiceImpl extends ServiceImpl<ShopProductDao, ShopProduct> implements ShopProductService {

    @Override
    public Integer reduceProduct(Integer id, Integer num) {
        log.info("用户下单，商品id=" + id + ",商品数量=" + num);
        ShopProduct shopProduct = this.getById(id);
        if (shopProduct.getNum() < num) {
            return -1;
        }
        shopProduct.setNum(shopProduct.getNum()-num).updateById();
        return num;
    }
}
